#include "debouncehandler.h"

void DebounceHandler::triggerAction(QObject *sender, std::function<void()> action, int delay) {
    if (m_timers.contains(sender)) {
        m_timers[sender]->stop(); // 停止已有计时器
    }
    QTimer *timer = new QTimer(this);
    timer->setSingleShot(true);
    connect(timer, &QTimer::timeout, [=]() {
        action();
        timer->deleteLater();
        m_timers.remove(sender);
    });
    m_timers[sender] = timer;
    timer->start(delay);
}
